local bashi = fk.CreateSkill {
  name = "bashi$",
}

bashi:addEffect(fk.AskForCardResponse, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
      table.find(Fk:currentRoom().alive_players, function(p) return p.kingdom == "wu" and p ~= player end) and
      ((data.cardName and (data.cardName == "slash" or data.cardName == "jink")) or
      (data.pattern and Exppattern:Parse(data.pattern):matchExp("slash,jink")))
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#bashi-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {}
    for _, name in ipairs({"slash", "jink"}) do
      local card = Fk:cloneCard(name)
      if data.pattern then
        if Exppattern:Parse(data.pattern):match(card) then
          table.insert(choices, name)
        end
      elseif data.cardName and data.cardName == name then
        table.insert(choices, name)
      end
    end
    local name = room:askForChoice(player, choices, self.name, "#bashi-choice")
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if p.kingdom == "wu" and p:isAlive() then
        local cardResponded = room:askForResponse(p, name, name, "#bashi-ask:"..player.id.."::"..name, true)
        if cardResponded then
          room:responseCard({
            from = p,
            card = cardResponded,
            skipDrop = true,
          })
          data.result = cardResponded
          data.result.skillName = self.name
          return true
        end
      end
    end
  end,
})

return bashi